//
//  AXFSettingController.m
//  Setting
//
//  Created by freak on 2016/11/20.
//  Copyright © 2016年 freak. All rights reserved.
//

#import "AXFSettingController.h"
#import "AXFLoginViewController.h"
#import "AXFHomeController.h"
#import "AXFWhiteNavView.h"
static NSString *cellID = @"cellID";
@interface AXFSettingController ()<UITableViewDelegate,UITableViewDataSource,AXFWhiteNavViewDelegate>
@property (nonatomic,weak) UITableViewCell *cell;
@end

@implementation AXFSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AXFWhiteNavView *whiteNavView = [[AXFWhiteNavView alloc] init];
    
    [whiteNavView setTitleName:@"设置" andFunctionName:nil];
    
    whiteNavView.delegate = self;
    
    [self.view addSubview:whiteNavView];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    
    [self.view addSubview:tableView];
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    //    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 200,[UIScreen mainScreen].bounds.size.width ,400 )];
    //
    //    //view.backgroundColor = [UIColor colorWithWhite:0.9 alpha:05];
    //
    //    [self.tableView addSubview:view];
    
    tableView.tableFooterView = [[UIView alloc] init];
    
    [whiteNavView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.mas_equalTo(kNAVBARH + 20);
    }];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(whiteNavView.mas_bottom);
        make.left.right.bottom.offset(0);
    }];
}

- (void)backToViewController
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    self.navigationController.navigationBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 3;
    }
    else
    {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = @"分享给朋友";
        return cell;
    }
    else if (indexPath.section == 0 && indexPath.row == 1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = @"关于我们";
        
        return cell;
        
    }
    else if (indexPath.section == 0 && indexPath.row == 2)
    {
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID]
        ;
        
        cell.textLabel.text = @"清除缓存";
        cell.detailTextLabel.text = @"4.6M";
        _cell = cell;
        return cell;
    }
    else
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        cell.textLabel.text = @"退出当前帐号";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.textAlignment  = NSTextAlignmentCenter;
        
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return 10;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 &&  indexPath.row == 0) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"分享到" message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
        [alert addAction:[UIAlertAction actionWithTitle:@"微信好友" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"weChat");
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"新浪微博" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"sina");
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"QQ空间" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"QQ空间");
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"微信朋友圈" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"微信朋友圈");
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            NSLog(@"点击了取消按钮");
        }]];
        
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        
        UIViewController *viewController = [[UIViewController alloc] init];
        
        viewController.view.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"AboutXF"].CGImage);
        
        
        [self.navigationController pushViewController:viewController animated:YES];
        
    }
    if (indexPath.section == 0 && indexPath.row == 2) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定清除缓存？" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:0 handler:^(UIAlertAction * _Nonnull action) {
            _cell.detailTextLabel.text = @"0M";
            NSLog(@"");
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"");
        }]];
        [self presentViewController:alert animated:YES completion:nil];
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        AXFLoginViewController *axfLoginvc = [[AXFLoginViewController alloc] init];
        [self.navigationController pushViewController:axfLoginvc animated:YES];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToHome" object:nil];
            }
    
}




@end
